<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:fmt="http://java.sun.com/jstl/fmt"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:sf="http://www.springframework.org/tags/faces"
	template="/WEB-INF/layout/login-template.xhtml">

  <ui:define name="jsUI">
//<![CDATA[
     function customLoadFunctionIE() {
         var loginField=document.getElementById('j_username');
         if(loginField != null
            && loginField.getAttribute('readonly') == true){
            //syntax correct, but focus failed!
           setFieldFocus('j_password');
         } else {
           setFieldFocus('j_username');
         }
     };

    function setFieldFocus(fieldName){
        setTimeout('document.getElementById("'+fieldName+'").focus()',10);
    }

    function customLoadFunctionFfx() {

         var loginField=document.getElementById('j_username');
         if(loginField != null
            && loginField.getAttribute('readonly') == ''){
           setFieldFocus('j_password');
         } else {
           setFieldFocus('j_username');
         }
     };

     if (window.attachEvent)
	 {
       window.attachEvent('onload', customLoadFunctionIE);
	 }
	 else
	 {
	   window.addEventListener("DOMContentLoaded", customLoadFunctionFfx, false);
	 }
//]]>
  </ui:define>
  <ui:define name="body">
		<h:form id="loginForm" prependId="false">
		 	<c:if test="${connexionActions.authenticated == 'FAILURE' }">
		 		<c:if test="${SPRING_SECURITY_LAST_EXCEPTION.message == 'Bad credentials' }">
     				<span id="infomessage" class="error" >
				    <h:outputText value=" #{msg.matricule_password}"/>
			 	   </span>
				 </c:if>
				<c:if test="${SPRING_SECURITY_LAST_EXCEPTION.message != 'Bad credentials' }">
     				<span id="infomessage" class="error" >
			 	   <h:outputText value="Ici"/>
			 	   </span>
				 </c:if>
			 </c:if>
			 <br/>
			 <h:message styleClass="error" for="j_username" showDetail="true"
						showSummary="true" />
						<br/>
			<h:message styleClass="error" for="j_password" showDetail="true"
						showSummary="true" />

		<br /><br /><br />
			<rich:panel style="width:360px">
				<f:facet name="header">#{msg.auth_ttl} </f:facet>
				<h:panelGrid columns="1" style="text-align:left;">
					<h:outputLabel for="j_username" value="#{msg.login_lbl} :"
						style="white-space:nowrap;" />
					<sf:clientTextValidator required="true"
						invalidMessage="#{msg.mandatory_field}">
						<h:inputText id="j_username" required="true" readonly="false" />
					</sf:clientTextValidator>
					<h:outputText value=" " />

					<h:message styleClass="error" for="j_username" showDetail="true"
						showSummary="true" />

					<h:outputLabel for="j_password" value="#{msg.password_lbl} :"
						style="white-space:nowrap;" />
					<sf:clientTextValidator required="true"
						invalidMessage="#{msg.mandatory_field}">
						<h:inputSecret id="j_password" required="true" />
					</sf:clientTextValidator>
					<h:outputText value=" " />

					<h:message styleClass="error" for="j_password" showDetail="true"
						showSummary="true" />

			    </h:panelGrid>
				<rich:spacer height="15" />
				<h:messages styleClass="error" globalOnly="true" />
				<span id="infomessage" class="error" >
			    <h:outputText value="#{SPRING_SECURITY_LAST_EXCEPTION.message}"/>
			    </span>

				<c:if test="${sessionScope.viewExpired != null}">
					<h:outputText value="${sessionScope.viewExpired}"
						styleClass="error" />
					<br />
				</c:if><br />
				<h:commandButton id="login" processIds="*"
					action="#{connexionActions.doLogin}" value="#{msg.login_btn}" />
			</rich:panel>
    </h:form>
  </ui:define>
</ui:composition>
